<?php
/****
	工厂模式
****/
header('Content-type:text/html;charset=GB2312');
//共同接口
Interface Db{
	public function connect();
}

Interface Factory{
	public function getDb();
}


class DbMysql implements Db{
	public function connect(){
		echo "连上了Mysql\r\n";
	}
}
class DbSqlite implements Db{
	public function connect(){
		echo "连上了Sqlite\r\n";
	}
}

class MysqlFactory implements Factory{
	public function getDb(){
		return new DbMysql();
	}
}
class SqliteFactory implements Factory{
	public function getDb(){
		return new DbSqlite();
	}
}

// ======服务端添加oracle类=====
//前面的代码不用改
class DbOracle implements Db{
	public function connect(){
		echo "连上了Oracle\r\n";
	}
}

class OracleFactory implements Factory{
	public function getDb(){
		return new DbSqlite();
	}
}


// ======客户端开始=====
$fact = new MysqlFactory();
$db = $fact->getDb();
$db->connect();


$fact = new SqliteFactory();
$db = $fact->getDb();
$db->connect();


//在面向对象设计法则中，重要的开闭原则，对于修改是封闭的，对于扩展是开放的
